package cn.hongsw.taskschedule.controller;

import cn.hongsw.taskschedule.factory.PageFactory;
import cn.hongsw.taskschedule.model.DataSourceInfo;
import cn.hongsw.taskschedule.service.DataSourceInfoService;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 数据源-控制器
 *
 * @author :hongsw
 * @date :2021-05-19 14:06
 */
@RestController
@RequestMapping("dataSource")
public class DataSourceController {

    @Resource
    private DataSourceInfoService dataSourceInfoService;

    /**
     * 新增数据源
     *
     * @param dataSourceInfo 数据源信息
     * @return boolean
     * @author hongsw
     * @date 2021/5/19 14:41
     **/
    @PostMapping
    public boolean add(DataSourceInfo dataSourceInfo) {
        return dataSourceInfoService.addDataSource(dataSourceInfo);
    }

    @GetMapping
    public Page<DataSourceInfo> page() {
        return dataSourceInfoService.page(PageFactory.defaultPage());
    }


    @DeleteMapping("{id}")
    public boolean delete(@PathVariable Long id) {
        return dataSourceInfoService.deleteDataSource(id);
    }
}
